package com.eisei.factory.tbl.dao.impl;

import java.math.BigInteger;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.eisei.factory.dao.impl.GenericDaoImpl;
import com.eisei.factory.tbl.TblCatRolEntity;
import com.eisei.factory.tbl.TblRelGrupoRolEntity;
import com.eisei.factory.tbl.TblUsuariosEntity;
import com.eisei.factory.tbl.dao.TblUsuariosDAO;

@Transactional
@Repository
public class TblUsuariosDAOImpl extends GenericDaoImpl<TblUsuariosEntity, Long>
        implements TblUsuariosDAO {

    public TblUsuariosDAOImpl() {
        super(TblUsuariosEntity.class);
    }

    public TblUsuariosDAOImpl(final Class<TblUsuariosEntity> clazz,
            final SessionFactory sessionFactory) {
        super(TblUsuariosEntity.class, sessionFactory);
    }

    @Override
    public List<TblRelGrupoRolEntity> findByGrupoRol(
            final TblRelGrupoRolEntity tblRelGrupoRolEntity) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<TblUsuariosEntity> findByRol(
            final TblCatRolEntity tblCatRolEntity) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<TblCatRolEntity> findGruposByPkUsuario(final String pkUsuario,
            final BigInteger pkCatRol) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public TblUsuariosEntity findPkUsuario(final String pkUsuario) {
        final Session session = sessionFactory.getCurrentSession();
        final String hql = "SELECT u FROM TblUsuarios u WHERE u.pkUsuario=:pkUsuario";
        final Query q = session.createQuery(hql);
        q.setParameter("pkUsuario", pkUsuario);
        return (TblUsuariosEntity) q.uniqueResult();
    }

    @Override
    public List<TblCatRolEntity> findRolesByPkUsuario(final String pkUsuario,
            final BigInteger pkCatRol) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Integer getCount() {
        final Session session = sessionFactory.getCurrentSession();
        final Query q = session
                .createQuery("select count(u) from TblUsuarios u");
        final Number count = (Number) q.uniqueResult();
        return count.intValue();
    }

}
